﻿using System.Windows;
using EbbinghausWord.BLL;
using Microsoft.Phone.Controls;

namespace EbbinghausWord.Pages
{
    public partial class Option : PhoneApplicationPage
    {
        public Option()
        {
            InitializeComponent();

            this.DataContext = new UserConfig();
        }

        #region private field

        /// <summary>
        /// 记忆排序选项的原始值
        /// </summary>
        private int orderTypeSource = new UserConfig().OrderType;
        #endregion

        #region callback

        private void clearCache_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("清除学习记录将清除您所有的学习记录，导致当前的学习进度丢失，确认清除吗？", "提示", MessageBoxButton.OKCancel)
                           == MessageBoxResult.OK)
            {
                WordBookManager.ClearWorkbook();
                Tools.ShowMessage("清除学习记录成功！");
            }
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            //如果更改了排序方式，则需要单词学习页面重新加载
            if (new UserConfig().OrderType != orderTypeSource)
            {
                WordBookManager.IsNeedReflesh = true;
            }
            base.OnNavigatedFrom(e);
        }
        #endregion

    }
}